package org.testis.gui.mvc.view.dynamicmap;

import org.testis.gui.mvc.view.*;
import java.awt.Frame;
import java.awt.event.WindowListener;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import java.beans.PropertyChangeEvent;
import org.testis.gui.mvc.controller.dynamicmap.DynamicMapController;
import org.testis.gui.mvc.controller.DynamicMapControllerList;
import org.testis.gui.mvc.utilities.ParameterTableModel;
import org.testis.gui.mvc.utilities.Validatable;
import org.testis.gui.mvc.utilities.ValidationUtils;

/**
 *
 * @author  Cahit Emir Erel
 */
public class DynamicMapView extends AtofBaseDialog
        implements AbstractViewPanel, Validatable {

    private static final long serialVersionUID = 9345332L;
    private boolean m_addNewContainer;
    private boolean m_editMode;
    private String m_windowTitle;
    private String[] m_choices;

    /**
     * Constructs an empty Dialog either in edit or add mode specified by editMode parameter
     * @param  parent - Frame to show the Dialog in
     * @param modal - modality of the Dialog
     * @param editMode - edit mode of the Dialog
     */
    private DynamicMapView(Frame parent,
            boolean modal,
            boolean editMode) {
        super(parent,
                modal);
        m_editMode = editMode;
        if (editMode) {
            m_windowTitle = "Edit Object";
        } else {
            m_windowTitle = "Add Object";
        }
        initComponents();
    }

    /**
     * Constructs an empty Dialog either in edit or add mode specified by editMode parameter and initial Parameter Model
     * @param  parent - Frame to show the Dialog in
     * @param modal - modality of the Dialog
     * @param editMode - edit mode of the Dialog
     * @param tableModel - Parameter Model to view in the Parameter Table
     */
    public DynamicMapView(Frame displayFrame,
            boolean modal,
            boolean editMode,
            boolean addNewContainer,
            ParameterTableModel tableModel) {
        this(displayFrame,
                modal,
                editMode);
        setAddNewContainer(addNewContainer);
        parameterTable.setModel(tableModel);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        saveButton = new javax.swing.JButton();
        addParameterButton = new javax.swing.JButton();
        parameterScrollPane = new javax.swing.JScrollPane();
        parameterTable = new javax.swing.JTable();
        removeParameterButton = new javax.swing.JButton();
        btnLanguageVariable = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        valueLabel = new javax.swing.JLabel();
        valueComboChoice = new javax.swing.JComboBox();
        parameterChoice = new java.awt.Choice();
        parameterLabel = new javax.swing.JLabel();
        typeChoice = new java.awt.Choice();
        typeLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        nameLabel = new javax.swing.JLabel();
        groupTypeLabel = new javax.swing.JLabel();
        groupTypeTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(m_windowTitle);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        String label;
        if (m_editMode) {
            label = "Save Changes";
        } else {
            label = "Add Dynamic Map Object";
        }
        saveButton.setText(label);
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        addParameterButton.setText("Add Parameter");
        addParameterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addParameterButtonActionPerformed(evt);
            }
        });

        parameterTable.getTableHeader().setReorderingAllowed(false);
        parameterScrollPane.setViewportView(parameterTable);

        removeParameterButton.setText("Remove Parameter");
        removeParameterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeParameterButtonActionPerformed(evt);
            }
        });

        btnLanguageVariable.setText("Language Variable");
        btnLanguageVariable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLanguageVariableActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(223, 219, 219));

        valueLabel.setFont(new java.awt.Font("Dialog", 1, 11));
        valueLabel.setText("Value:");

        valueComboChoice.setEditable(true);
        valueComboChoice.setModel(new javax.swing.DefaultComboBoxModel(new Object[0]));
        valueComboChoice.setEnabled(false);
        valueComboChoice.setLightWeightPopupEnabled(false);
        valueComboChoice.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                valueComboChoiceItemStateChanged(evt);
            }
        });
        valueComboChoice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                valueComboChoiceActionPerformed(evt);
            }
        });

        parameterChoice.setEnabled(false);
        parameterChoice.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                parameterChoiceItemStateChanged(evt);
            }
        });

        parameterLabel.setFont(new java.awt.Font("Dialog", 1, 11));
        parameterLabel.setText("Parameter:");

        typeChoice.setEnabled(false);
        typeChoice.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                typeChoiceItemStateChanged(evt);
            }
        });

        typeLabel.setFont(new java.awt.Font("Dialog", 1, 11));
        typeLabel.setText("Type:");

        nameTextField.setFont(new java.awt.Font("Dialog", 0, 11));
        nameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameTextFieldActionPerformed(evt);
            }
        });
        nameTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                nameTextFieldFocusLost(evt);
            }
        });

        nameLabel.setFont(new java.awt.Font("Dialog", 1, 11));
        nameLabel.setText("Name:");

        groupTypeLabel.setFont(new java.awt.Font("Dialog", 1, 11));
        groupTypeLabel.setText("Group Type:");

        groupTypeTextField.setEditable(false);
        groupTypeTextField.setFont(new java.awt.Font("Dialog", 0, 11));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(groupTypeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40)
                        .addComponent(groupTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(55, 55, 55)
                        .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(typeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(parameterLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(valueLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(parameterChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(typeChoice, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(valueComboChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(groupTypeLabel)
                    .addComponent(groupTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(nameLabel)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(typeLabel)
                    .addComponent(typeChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(parameterLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(parameterChoice, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(valueLabel)
                    .addComponent(valueComboChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        //valueComboChoice.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        //new String[] { "" }

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnLanguageVariable, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                            .addComponent(removeParameterButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(addParameterButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(saveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(parameterScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addParameterButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeParameterButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLanguageVariable)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveButton))
                    .addComponent(parameterScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addParameterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addParameterButtonActionPerformed

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationAddParameter();
}//GEN-LAST:event_addParameterButtonActionPerformed

    private void removeParameterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeParameterButtonActionPerformed

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationRemoveParameter(parameterTable.getSelectedRow());
}//GEN-LAST:event_removeParameterButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed

        if (!validateForm()) {
            return;
        }
        saveButton.setEnabled(false);
        if (m_editMode) {
            //DynamicMapControllerList.newInstance().getDynamicMapTreeController().operationGetSelectedDesignPart();
            DynamicMapControllerList.newInstance().getDynamicMapController().
                    operationSaveNewObject(nameTextField.getText(),
                    typeChoice.getSelectedItem(),
                    (ParameterTableModel) parameterTable.getModel());
        } else {
            DynamicMapControllerList.newInstance().getDynamicMapController().
                    operationAddNewObject(nameTextField.getText(),
                    (ParameterTableModel) parameterTable.getModel(),
                    typeChoice.getSelectedItem(),
                    isAddNewContainer());
        }

        this.dispose();
}//GEN-LAST:event_saveButtonActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

        WindowListener[] listeners = getWindowListeners();
        for (int i = 0; i < listeners.length; i++) {
            this.removeWindowListener(listeners[i]);
        }
        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationCloseWindow();
        this.dispose();
    }//GEN-LAST:event_formWindowClosed

    private void typeChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_typeChoiceItemStateChanged

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationChangeType(typeChoice.getSelectedItem());
        //typeChoice.setEnabled(false);
}//GEN-LAST:event_typeChoiceItemStateChanged

    private void parameterChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_parameterChoiceItemStateChanged
        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationChangeParameter(parameterChoice.getSelectedItem());
}//GEN-LAST:event_parameterChoiceItemStateChanged

    private void valueComboChoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_valueComboChoiceActionPerformed

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationChangeValue(valueComboChoice.getSelectedItem().toString());
    }//GEN-LAST:event_valueComboChoiceActionPerformed

    private void nameTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFieldFocusLost

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationChangeName(nameTextField.getText());
    }//GEN-LAST:event_nameTextFieldFocusLost

    private void valueComboChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_valueComboChoiceItemStateChanged

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationChangeValue(evt.getItemSelectable().getSelectedObjects()[0].toString());
}//GEN-LAST:event_valueComboChoiceItemStateChanged

    private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextFieldActionPerformed

        DynamicMapControllerList.newInstance().getDynamicMapController().
                operationChangeName(nameTextField.getText());
    }//GEN-LAST:event_nameTextFieldActionPerformed

private void btnLanguageVariableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLanguageVariableActionPerformed
    DynamicMapControllerList.newInstance().getDynamicMapController().
            operationGetLanguageVariables();


}//GEN-LAST:event_btnLanguageVariableActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addParameterButton;
    private javax.swing.JButton btnLanguageVariable;
    private javax.swing.JLabel groupTypeLabel;
    private javax.swing.JTextField groupTypeTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private java.awt.Choice parameterChoice;
    private javax.swing.JLabel parameterLabel;
    private javax.swing.JScrollPane parameterScrollPane;
    private javax.swing.JTable parameterTable;
    private javax.swing.JButton removeParameterButton;
    private javax.swing.JButton saveButton;
    private java.awt.Choice typeChoice;
    private javax.swing.JLabel typeLabel;
    private javax.swing.JComboBox valueComboChoice;
    private javax.swing.JLabel valueLabel;
    // End of variables declaration//GEN-END:variables

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        //System.out.println(evt.getPropertyName() + " = " + evt.getNewValue());
        if (evt.getPropertyName().equals(
                DynamicMapController.SHOW_ADD_DYNAMIC_MAP)) {
            this.centerParent();
        } else if (evt.getPropertyName().equals(
                DynamicMapController.CHANGE_GROUP_TYPE)) {
            String gType = (String) evt.getNewValue();
            typeChoice.removeAll();
            typeChoice.add("");
            m_choices = DynamicMapControllerList.newInstance().
                    getDynamicMapController().operationGetTypes(gType);
            for (int i = 0; i < m_choices.length; i++) {
                typeChoice.add(m_choices[i]);
            }
            m_choices = null;
            if (!m_editMode && !isAddNewContainer()) {
                typeChoice.setEnabled(true);
            } else {
                typeChoice.setEnabled(false);
            }
            groupTypeTextField.setText(gType);
            groupTypeTextField.repaint();
        } else if (evt.getPropertyName().equals(DynamicMapController.CHANGE_TYPE)) {
            String type = (String) evt.getNewValue();
            parameterChoice.removeAll();
            parameterChoice.add("");
            if (!type.equals("")) {
                if (type.equals("UIDeviceMapContainer")) {
                    typeChoice.add("UIDeviceMapContainer");
                }
                m_choices = DynamicMapControllerList.newInstance().
                        getDynamicMapController().operationGetParameters(type);
                DynamicMapControllerList.newInstance().getDynamicMapController().
                        operationRemoveAllParameters();
                for (int i = 0; i < m_choices.length; i++) {
                    parameterChoice.add(m_choices[i]);
                    DynamicMapControllerList.newInstance().
                            getDynamicMapController().operationAddParameter(
                            m_choices[i]);
                }
                m_choices = null;
                parameterChoice.setEnabled(true);
            } else {
                parameterChoice.setEnabled(false);
            }
            typeChoice.select(type);
            typeChoice.repaint();
            parameterChoice.repaint();
        } else if (evt.getPropertyName().equals(
                DynamicMapController.CHANGE_PARAMETER)) {
            String parameter = (String) evt.getNewValue();
            valueComboChoice.removeAllItems();
            if (parameter.equals("")) {
                valueComboChoice.setEnabled(false);
            } else {
                if (parameter.equals("AbstractId")) {
                    m_choices =
                            DynamicMapControllerList.newInstance().
                            getDynamicMapController().operationGetAbstractValues(
                            typeChoice.getSelectedItem());
                    for (int i = 0; i < m_choices.length; i++) {
                        valueComboChoice.addItem(makeObject(m_choices[i]));
                    }
                    m_choices = null;
                }
                valueComboChoice.setEnabled(true);
            }
            valueComboChoice.repaint();
            parameterChoice.repaint();
        } else if (evt.getPropertyName().equals(DynamicMapController.CHANGE_NAME)) {
            nameTextField.setText((String) evt.getNewValue());
            nameTextField.repaint();
        } else if (evt.getPropertyName().equals(DynamicMapController.ADD_PARAMETER)) {
            parameterTable.setModel((ParameterTableModel) evt.getNewValue());
            parameterTable.updateUI();
        } else if (evt.getPropertyName().equals(
                DynamicMapController.REMOVE_SELECTED_PARAMETER)) {
            parameterTable.setModel((ParameterTableModel) evt.getNewValue());
            parameterTable.updateUI();
        } else if (evt.getPropertyName().equals(
                DynamicMapController.REMOVE_ALL_PARAMETERS)) {
            parameterTable.setModel((ParameterTableModel) evt.getNewValue());
            parameterTable.updateUI();
        } else if (evt.getPropertyName().equals(
                DynamicMapController.SELECT_PARAMETER)) {
        }
    }

    public Object makeObject(final String item) {
        return new Object() {

            @Override
            public String toString() {
                return item;
            }
        };
    }

    private boolean isAddNewContainer() {
        return m_addNewContainer;
    }

    private void setAddNewContainer(boolean addNewContainer) {
        m_addNewContainer = addNewContainer;
    }

    /**
     * Returns true if the selection made by the user in the view are valid
     * @return true if the selection made by the user in the view are valid 
     */
    @Override
    public boolean validateForm() {
        boolean valid = true;
        StringBuilder builder = new StringBuilder();
        if (ValidationUtils.isEmpty(nameTextField.getText())) {
            builder.append("Name must not be empty.\n");
            valid = false;
        }
        if (ValidationUtils.isEmpty(typeChoice.getSelectedItem())) {
            builder.append("Type must not be empty.\n");
            valid = false;
        }
        if (ValidationUtils.isEmpty(groupTypeTextField.getText())) {
            builder.append("Group Type can not be empty.\n");
            valid = false;
        }
        if (!valid) {
            JOptionPane.showMessageDialog(null,
                    builder.toString(),
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
        return valid;
    }
}
